/*
 * Author: nicolas.bredeche(@)upmc.fr
 * Created on 2005-08-31 -- Refactored on 2014-01-06 
 */

package picoevo.core;

import java.util.ArrayList;

import picoevo.tools.*;

public abstract class PopulationObject extends EvolutionObject implements PopulationInterface {

	// ### Data ###
	
	protected ArrayList<Individual> _individuals = new ArrayList<Individual>();

	private String _name = new String ("unnamed element");	

	// ### Constructor(s) ###
	

	public PopulationObject ( String __populationName )
	{
		_name = __populationName;
	}

	// ### Accessing ###

	public void setName (String __name)
	{
		_name = __name;
	}
	
	public String getName ()
	{
		return (_name);
	}
	
	/** 
	 * return actual population size
	 */
	public int getSize ()
	{
		if ( this._individuals == null )
			Display.error(this.getClass().getName()+" : trying to get size of population while population not initialised.");
		return ( this._individuals.size() );
	}
	
	// ### Other methods ###

	public void displayInformation()
	{
		Display.info("### Population Information : summary ###");
		Display.info("Population name : " + this._name );
		Display.info("Population size : " + this.getSize() );
	    Display.info("\n");
	    for ( int i = 0 ; i != _individuals.size() ; i++ )
	    		this.getIndividual(i).displayInformation();
	}
	
	abstract public void add ( Individual __ind );
	
	public Individual getIndividual ( int __index )
	{
		return ((Individual)_individuals.get(__index));
	}
	
	public ArrayList getPopulation() 
	{
		return this._individuals;
	}
	
	public void reset ()
	{
		this._individuals = null;
	}



}
